#include "Camera.h"
#include "Visualisation.h"
CCamera::CCamera(void){}//:m_yaw(0), m_pitch(0), m_roll(0), m_position(D3DXVECTOR3(0, 0, 0)){}

CCamera::~CCamera(void){}

void CCamera::calculateFPSViewMatrix(D3DXVECTOR3 position, float pitch, float yaw, float roll)
{
	D3DXVECTOR3 up(0.0f,1.0f,0.0f);
	D3DXVECTOR3 look(0.0f,0.0f,1.0f);
	D3DXVECTOR3 right(1.0f,0.0f,0.0f);

	//yaw rotation
	D3DXMATRIX yawMatrix;
	D3DXMatrixRotationAxis(&yawMatrix, &up, yaw);

	D3DXVec3TransformCoord(&look, &look, &yawMatrix);
	D3DXVec3TransformCoord(&right, &right, &yawMatrix);

	//pitch rotation
	D3DXMATRIX pitchMatrix;
	D3DXMatrixRotationAxis(&pitchMatrix, &right, pitch);

	D3DXVec3TransformCoord(&look, &look, &pitchMatrix);
	D3DXVec3TransformCoord(&up, &up, &pitchMatrix);

	//roll rotation
	D3DXMATRIX rollMatrix;
	D3DXMatrixRotationAxis(&rollMatrix, &look, roll);

	D3DXVec3TransformCoord(&right, &right, &rollMatrix);
	D3DXVec3TransformCoord(&up, &up, &rollMatrix);


	//fill the view matrix
	D3DXMATRIX viewMatrix;
	D3DXMatrixIdentity(&viewMatrix);

	viewMatrix._11 = right.x; viewMatrix._12 = up.x; viewMatrix._13 = look.x;
	viewMatrix._21 = right.y; viewMatrix._22 = up.y; viewMatrix._23 = look.y;
	viewMatrix._31 = right.z; viewMatrix._32 = up.z; viewMatrix._33 = look.z;

	viewMatrix._41 = - D3DXVec3Dot( &position, &right );
	viewMatrix._42 = - D3DXVec3Dot( &position, &up );
	viewMatrix._43 = - D3DXVec3Dot( &position, &look );

	//set the view matrix
	VIS->getDevice()->SetTransform( D3DTS_VIEW, &viewMatrix );

}

//void CCamera::yaw(float amount)
//{
//	m_yaw+=amount;
//}
//
//void CCamera::pitch(float amount)
//{
//	m_pitch+=amount;
//}
//
//void CCamera::roll(float amount)
//{
//	m_roll+=amount;
//}
//
//void CCamera::moveForward(float amount)
//{
//	m_position+=m_look*amount;
//}
//
//void CCamera::moveBackward(float amount)
//{
//	m_position+=m_look*-amount;
//}
//
//void CCamera::strafeLeft(float amount)
//{
//	m_position+=m_right*-amount;
//}
//
//void CCamera::strafeRight(float amount)
//{
//	m_position+=m_right*amount;
//}
//
//void CCamera::moveUp(float amount)
//{
//	m_position+=m_up*amount;
//}
//
//void CCamera::moveDown(float amount)
//{
//	m_position+=m_up*-amount;
//}
//
//void CCamera::setPosition(D3DXVECTOR3 position)
//{
//	m_position=position;
//}